<template>
  
  <div class="body">

  <div>
    <Family :activeIndex="'whisper'"></Family>
  </div>
  <!-- {{ list }} -->
  <!-- {{ detail }} -->
  <hr />
  <!-- {{ username }}
  {{ list }} -->

  

  <el-container class="layout-container-demo" style="height: 500px">
    <el-aside width="300px">
      <el-scrollbar>
        <div style="font-size: 14px; padding-left: 18px; padding-top: 10px"
          >近期消息</div
        >
        <ElMenu>
          <div class="user-message-list">
            <div
              v-for="d in list"
              class="message-item"
              @click="showDetail(d.user.uid)"
            >
              <img :src="d.exinfo.logo" class="avatar" />
              <div class="message-content">
                <div class="sender-name">{{ d.user.username }}</div>
                <div class="message-text">11111111</div>
              </div>
            </div>
          </div>
        </ElMenu>
      </el-scrollbar>
    </el-aside>

    <el-container>
      <el-header>
        <div class="original-div">
          <div>我的消息</div>
          <div
            ><el-icon><BellFilled /></el-icon
          ></div>
        </div>
      </el-header>

      <el-main>
        <el-scrollbar>
          <div>
            <div class="title">{{ username }}</div>
            <div v-for="d in detail" class="message-list">
              <div class="message-list-content min_h_100">
                <div
                  v-if="user.data.user.uid == d.senderId"
                  class="msg-item is-me"
                >
                  <img
                    :src="user.data.exinfo.logo"
                    alt=""
                    class="avatars"
                    style="float: right"
                  />
                  <div class="messages">
                    <div class="me">{{ d.content }} </div>
                  </div>
                </div>

                <div
                  v-if="user.data.user.uid != d.senderId"
                  class="msg-item not-me"
                >
                  <img
                    :src="logo ? logo : defaultimg"
                    alt=""
                    class="avatars"
                    style="float: left"
                  />
                  <div class="messagess" style="float: left">
                    <div class="notme">{{ d.content }}</div>
                  </div>
                </div>
              </div>
            </div>
            <div class="send-box">
              下<div class="row"></div>
              <div class="input-box"></div>
              <div class="row right"></div>
            </div>
          </div>
        </el-scrollbar>
      </el-main>
    </el-container>
  </el-container>

</div>
</template>

<script setup>
import Family from '../../comment/family.vue';
import { ref, onMounted } from 'vue';

import { useRouter } from 'vue-router';
import Api from '../../script/Api';
import { ElMenu, ElMessage, ElSubMenu } from 'element-plus';
import userstore from '../../store/user';
import { storeToRefs } from 'pinia';

const { user, isLogin } = storeToRefs(userstore());
const list = ref([]);
const query = () => {
  Api.get('/private', {}, (data) => {
    if (data.success) {
      list.value = data.data;
    } else {
      ElMessage.error(data.message);
    }
  });
};

query();

//#region 点击聊天对象

//#endregion

//#region 获取id对象的聊天内容
const detail = ref([]);
const defaultimg = ref('https://api.gongzhiyun.fun/files/31');
const showUid = ref([]);
const username = ref([]);
const logo = ref([]);

const getDialogue = (id) => {
  detail.value = [];
  Api.get(`/private/${id}`, {}, (data) => {
    if (data.success) {
      detail.value = data.data;
    } else {
      ElMessage.error(data.message);
    }
  });
};

const queryByUid = (id) => {
  showUid.value = '';
  Api.get(`/user/queryById/${id}`, {}, (data) => {
    if (data.success) {
      logo.value = data.data.exinfo.logo;
      username.value=data.data.user.username
    } else {
      ElMessage.error(data.message);
    }
  });
};
const showDetail = (id) => {
  getDialogue(id);
  queryByUid(id);
};

//#endregion
</script>

<style scoped>

.body {
  /* background: url(//s1.hdslb.com/bfs/static/blive/blfe-message-web/static/img/light_bg.8e46311e.png)
    top / cover no-repeat fixed; */

  padding: 0;
  margin: 0;
}

.selected{
  background-color: #f0f0f0;
}

.messagess {
  float: right;
  max-width: 480px;
  margin: 15px 5px;
  position: relative;
  overflow: hidden;
  color: #333;
}

.notme {
  background: #fff;
  /* border-radius: 16px 0 16px 16px; */
  position: relative;
  z-index: 1;
  line-height: 1.5;
  font-size: 14px;
  min-height: 37px;
  padding: 8px 16px;
  word-wrap: break-word;
  word-break: break-word;
  border-radius: 0 16px 16px 16px;
  overflow: hidden;
}

.avatars {
  display: block;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  -ms-flex-negative: 0;
  flex-shrink: 0;
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  margin-top: 15px;
}
.me {
  background: #80b9f2;
  border-radius: 16px 0 16px 16px;
  position: relative;
  z-index: 1;
  line-height: 1.5;
  font-size: 14px;
  min-height: 37px;
  padding: 8px 16px;
  word-wrap: break-word;
  word-break: break-word;
  /* border-radius: 0 16px 16px 16px; */
  overflow: hidden;
}

.is-me {
}

.messages {
  float: right;
  max-width: 480px;
  margin: 15px 5px;
  position: relative;
  overflow: hidden;
  color: #fff;
}

/* 
.message .message-content[data-v-2a2a18ce]:not(.is-img) {
    position: relative;
    z-index: 1;
}
.message .message-content.is-me[data-v-2a2a18ce] {
    background: #80b9f2;
    border-radius: 16px 0 16px 16px;
}
.message .message-content[data-v-2a2a18ce] {
    line-height: 1.5;
    font-size: 14px;
    min-height: 37px;
    padding: 8px 16px;
    word-wrap: break-word;
    word-break: break-word;
    border-radius: 0 16px 16px 16px;
    overflow: hidden;
    background: #fff;
}

.is-me .message {
    position: relative;
    float: right;
    color: #fff;
}

.message {
    float: left;
    max-width: 480px;
    margin: 0 10px;
    position: relative;
    overflow: hidden;
    color: #333;
}



.is-me .avatar[data-v-2a2a18ce] {
    float: right;
    background-image: url(//static.hdslb.com/images/member/noface.gif);
}
.msg-item .avatar[data-v-2a2a18ce], .msg-item .message[data-v-2a2a18ce] {
    float: left;
}
.avatar[data-v-2a2a18ce] {
    display: block;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    -ms-flex-negative: 0;
    flex-shrink: 0;
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    background-image: url(//static.hdslb.com/images/member/noface.gif);
    float: left;
} */

.msg-item {
  min-height: 48px;
  padding: 0 16px 16px;
  overflow: hidden;
  position: relative;
}

.msg-more {
  padding: 16px 0 0;
  text-align: center;
  color: #23ade5;
  min-height: 38px;
}

.message-list-content {
  overflow: auto;
}

.min_h_100 {
  min-height: 100% !important;
}

.title {
  height: 36px;
  -ms-flex-negative: 0;
  flex-shrink: 0;
  display: -webkit-box;
  display: -ms-flexbox;
  display: flex;
  -webkit-box-pack: center;
  -ms-flex-pack: center;
  justify-content: center;
  -webkit-box-align: center;
  -ms-flex-align: center;
  align-items: center;
  border-bottom: 1px solid #e9eaec;
  position: relative;
  text-align: center;
  color: #020202;
}
.message-list {
  -webkit-box-flex: 1;
  -ms-flex: 1;
  flex: 1;
  position: relative;
  overflow-x: hidden;
  overflow-y: scroll;
  background-color: #f4f5f7;
}

.send-box {
  height: 162px;
  border-top: 1px solid #d8d8d8;
  border-bottom-right-radius: 4px;
  background-color: #f4f5f7;
  -ms-flex-negative: 0;
  flex-shrink: 0;
  padding: 0 16px;
  position: relative;
  z-index: 2;
}

/* 原始div样式 */
.original-div {
  height: 42px;
  background-color: #fff;
  box-shadow: 0 2px 4px 0 rgba(121, 146, 185, 0.54);
  display: flex;
  -webkit-box-align: center;
  align-items: center;
  -webkit-box-pack: justify;
  -ms-flex-pack: justify;
  justify-content: space-between;
  padding: 0 16px;
  font-size: 15px;
  color: #666;
  border-radius: 4px;
}
.original-div-bottom {
  height: 42px;
  background-color: #fff;
  box-shadow: 0 2px 4px 0 rgba(121, 146, 185, 0.54);
  display: flex;
  -webkit-box-align: center;
  align-items: center;
  -webkit-box-pack: justify;
  -ms-flex-pack: justify;
  justify-content: space-between;
  padding: 0 16px;
  font-size: 15px;
  color: #666;
  border-radius: 4px;
}

.user-message-list {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 16px;
}

.message-item {
  display: flex;
  align-items: flex-start;
  cursor: pointer;
  padding: 8px;
  border: 1px solid #ddd;
  border-radius: 4px;
  transition: background-color 0.3s;
}

.message-item:hover {
  background-color: #f0f0f0;
}

.avatar {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  margin-right: 16px;
}

.message-content {
  flex: 1;
}

.sender-name {
  font-weight: bold;
  margin-bottom: 4px;
}

.message-text {
  color: #555;
}
</style>
